
<?php

//initialisation
if (!isset($portlet_shop_categories_ParentCategory))  $portlet_shop_categories_ParentCategory=null;
if (!isset($portlet_shop_categories_MultipleCategories))  $portlet_shop_categories_MultipleCategories="yes";
if (!isset($portlet_shop_categories_ColumnCount))  $portlet_shop_categories_ColumnCount=3;


if (getParameter("categoryId") && $portlet_shop_categories_MultipleCategories=="yes")
{
	
	
	?>
	
	<div class="shop_categories">
	<?php

   //     $parentCategory=$portlet_shop_categories_ParentCategory;
        if (getParameter("categoryId")!=null) $parentCategory=getParameter("categoryId");


$SQL="SELECT
shop_category.id,
shop_category.category,
shop_category.friendlyUrl,
shop_category.lib_$LANG as lib,
shop_category.parentCategoryId,
shop_category.portalId,
shop_category.image
FROM `shop_category`
WHERE parentCategoryId=$parentCategory AND  shop_category.portalId = ".$portalId."
Order by orderCmpnt asc";
//echo $SQL;
Portal_log($SQL);
$rs=ew_LoadRecordset($SQL);

if ($rs && $rs->RecordCount()>0) {

$count=$rs->RecordCount();
//echo $count;
$item_per_column=2;
//echo $item_per_column;
?>
<table width="100%">

<?php 
$i=0;
 while ( !$rs->EOF)  { 
 	
 	//$imgpath=;
 	
		  ?>
	<?php  if ($i%$item_per_column==0) { ?>  <tr valign="top"> <?php }?>
		  <td >
		<h2><?php echo $rs->fields["lib"]; ?></h2>
		<div>
		<div class="image border">
		<img width="98px" height="98px" alt="" src="<?php echo getFilesPath("shopcategory",false)."/".$rs->fields["image"]; ?>">
		</div>
		<div class="categories">
		<ul>
		<?php 
		
		$SQL="SELECT
		shop_category.id,
		shop_category.friendlyUrl,
		LOWER(shop_category.category) as category,
		shop_category.lib_$LANG as lib
		FROM `shop_category`
		WHERE parentCategoryId=".$rs->fields["id"]." AND  shop_category.portalId = ".$portalId."
		Order by lib asc";
		//echo $SQL;
		Portal_log($SQL);
		$rscategory=ew_LoadRecordset($SQL);
		if ($rscategory && $rscategory->RecordCount()>0) {
		while (!$rscategory->EOF)  {
            $url=createNiceUrl("pageName","catalogue","categoryId",$rscategory->fields["id"]);
            $furl=$rs->fields["friendlyUrl"];
            if ($furl!="") $url=$furl;
			?>

			<li><a href="<?php echo $url; ?>"><?php echo $rscategory->fields["lib"]; ?></a></li>
			<?php
			$rscategory->MoveNext();
		}}
		?>
		</ul>
		</div>
		</div>
		</td >

     <?php $i++;  if ($i%$item_per_column!=0) { ?> <td ><img src="/images/empty.png" width="20px" ></td> <?php }?>
		 <?php   if ($i%$item_per_column==0) { ?>  </tr>
		 <tr height="20px;"><td  colspan="<?php echo $colunm_count*2;?>"><img src="/images/empty.png" height="20px;" ></td></tr>
		 <?php }?>
		  	  <?php
			
		  $rs->MoveNext();    
		  }
		  ?>
		 
		 
		  </table>
		  
		  <?php
		  
		  
}else{

    ShowError($var_shop_nosubcategory);
}
?>
</div>
<?php


}
else{
	
	?>
	
	<div class="shop_main_categories ">

	<?php




      if (isset($portlet_shop_categories_TargetPage) && $portlet_shop_categories_TargetPage!="")
      {
      $pageName=$portlet_shop_categories_TargetPage;
      }else
      $pageName=getParameter("pageName");

    $parentCategory=null;
    if (getParameter("category")!=null)  $parentCategory=getObjByKey("shop_category","id","category",getParameter("category"),"portalId",$portalId);


    
    
    if ($parentCategory!=null)  {
        $parentCategory="parentCategoryId = $parentCategory";

    }else{
        $parentCategory="parentCategoryId = $portlet_shop_categories_ParentCategory";
        if ($portlet_shop_categories_ParentCategory==null || $portlet_shop_categories_ParentCategory=="") $parentCategory="parentCategoryId is NULL";
    }



$SQL="SELECT
shop_category.id,
shop_category.friendlyUrl,
LOWER(shop_category.category) as category,
CONCAT( UPPER( SUBSTRING( shop_category.lib_$LANG, 1, 1 ) ) , LOWER( SUBSTRING( shop_category.lib_$LANG, 2 ) ) ) as lib,
shop_category.parentCategoryId,
shop_category.portalId,
shop_category.image,
shop_category.description_$LANG as description
FROM `shop_category`
WHERE $parentCategory AND  shop_category.portalId = ".$portalId."
Order by orderCmpnt asc";
Portal_log($SQL);
 // echo $SQL;
$rs=ew_LoadRecordset($SQL);

if ($rs && $rs->RecordCount()>0) {

$count=$rs->RecordCount();
//echo $count;
$colunm_count=$portlet_shop_categories_ColumnCount;
$item_per_column=$count/$colunm_count;
$item_per_column=$colunm_count;
//echo $item_per_column;
?>


<?php 
$i=0;
 while ( !$rs->EOF)  { 

 	//$imgpath=getFilesPath("gallery",false)."/".$rs_gallery->fields["picture"];
$url=createNiceUrl("pageName",$pageName,"",$rs->fields["category"]);
     $furl=$rs->fields["friendlyUrl"];
     if ($furl!="") $url=$furl;
		  ?>

               <div class="border categoryholder" style="background-image: url(<?php echo getFilesPath("shopcategory",false)."/".$rs->fields["image"]; ?>)" >
		    <a class="" href="<?php echo $url ?>">
                <?php if ($rs->fields["image"]!="") { ?>
               <div class="image">
		<img  alt="" src="<?php echo getFilesPath("shopcategory",false)."/".$rs->fields["image"]; ?>">

		</div>

		<!--  <img  alt="" src="/apps/image.php?color=1B2426&cropratio=8:5&width=300&height=800&image=<?php echo getFilesPath("shopcategory",false)."/".$rs->fields["image"]; ?>">-->
               <?php } ?>
		<div class="category">
		 <a class="" href="<?php echo $url ?>"><h1>
		 <?php echo $rs->fields["lib"]; ?></h1>
		 <div class="description"><?php echo $rs->fields["description"]; ?></div>
		 </div>
		 </a>
               </div>


		  	  <?php
			
		  $rs->MoveNext();    
		  }
		  ?>
		 

		  
		  <?php
		  
		  
}
?>
</div>
<?php }?>